package com.oddfar.campus.business.controller;

import com.oddfar.campus.business.domain.Clqkxx;
import com.oddfar.campus.business.mapper.ClqkxxMapper;
import com.oddfar.campus.business.service.ClqkxxService;
import com.oddfar.campus.common.domain.PageResult;
import com.oddfar.campus.common.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/fjdcgl/clqkxx")
public class ClqkxxController {
    
    @Autowired
    private ClqkxxService clqkxxService;

    @Autowired
    private ClqkxxMapper clqkxxMapper;

    @RequestMapping(value = "/list", name = "查询车主列表")
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    public R list(Clqkxx clqkxx) {
        PageResult<Clqkxx> page;
        page = clqkxxService.page(clqkxx);
        return R.ok().put(page);
    }


    /**
     * 获取车辆详细信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @GetMapping(value = "/{mobile}", name = "获取车主详细信息")
    public R getInfo(@PathVariable("mobile") Long mobile) {
        return R.ok(clqkxxMapper.selectById(mobile));
    }

    /**
     * 新增车主信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @PostMapping(name = "新增车主信息")
    public R add(@RequestBody Clqkxx clqkxx) {
        return R.ok(clqkxxService.insertClqkxx(clqkxx));
    }

    /**
     * 修改车主信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @PutMapping(name = "修改车主信息")
    public R edit(@RequestBody Clqkxx clqkxx) {
        return R.ok(clqkxxService.updateClqkxx(clqkxx));
    }

    /**
     * 删除车主信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @DeleteMapping(value = "/{djxh}", name = "删除车主信息")
    public R remove(@PathVariable Long djxh) {
        return R.ok(clqkxxMapper.deleteClqkxx(djxh));
    }

    /**
     * 删除违章信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @DeleteMapping(value = "/dl/{uuid}", name = "删除车主信息")
    public R removewzxx(@PathVariable String uuid) {
        clqkxxMapper.setclsj(uuid);
        return R.ok(clqkxxMapper.deletewzxx(uuid));
    }
    
}
